package com.anthonybennis.blender.client.pages.keyboard;

import com.anthonybennis.blender.client.System;
import com.anthonybennis.blender.client.System.SCREEN_WIDTHS;
import com.anthonybennis.blender.client.Util;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;
import com.googlecode.mgwt.ui.client.widget.panel.scroll.ScrollPanel;

/**
 * 
 * @author Anthony
 */
public class TileDescriptionPanel 
{
	private final HTML _descriptionLabel = new HTML();
	private final ScrollPanel _descriptionPanel = new ScrollPanel();
	
	/**
	 * 
	 * @return
	 */
	public Widget createWidget()
	{
		_descriptionPanel.setWidth("100%");
		_descriptionLabel.setSize("100%", "100%");
		_descriptionPanel.add(_descriptionLabel);
		
		return _descriptionPanel;
	}
	
	protected void showDescription(String title, String shortcut, String desciption)
	{
		_descriptionPanel.setVisible(true);
		String startTaglargeTextSize = this.getLargeTextSizeForScreenSize(false);
		String endTaglargeTextSize = this.getLargeTextSizeForScreenSize(true);
		String startTagStandardTextSize = this.getStandardTextSizeForScreenSize(false);
		String endTagStandardTextSize = this.getStandardTextSizeForScreenSize(true);
		
		StringBuilder htmlBuilder = new StringBuilder();
		htmlBuilder.append(startTaglargeTextSize + shortcut + "    [" + title + "] " + endTaglargeTextSize);
		htmlBuilder.append("<br>");
		htmlBuilder.append(startTagStandardTextSize + desciption + endTagStandardTextSize);
		_descriptionLabel.setHTML(htmlBuilder.toString());
		_descriptionLabel.setWordWrap(true);
		Util.setFontColour(_descriptionLabel, "white");
		String rgb = Util.RGBToHex(64, 64, 64);
		Util.setBackground(_descriptionPanel, rgb);
	}
	
	private String getLargeTextSizeForScreenSize(boolean endTag)
	{
		String largeTextSize = "<h1>";
		
		if (System.getScreenWidth() == SCREEN_WIDTHS.STANDARD_WIDTH && endTag)
		{
			largeTextSize = "<//h1>";
		}
		else if (System.getScreenWidth() == SCREEN_WIDTHS.STANDARD_WIDTH)
		{
			largeTextSize = "<h1>";
		}
		else if (endTag)
		{
			largeTextSize = "<//h3>";
		}
		else
		{
			largeTextSize = "<h3>";
		}
		
		
		return largeTextSize;
	}
	
	private String getStandardTextSizeForScreenSize(boolean endTag)
	{
		String largeTextSize = "<h2>";
		
		if (System.getScreenWidth() == SCREEN_WIDTHS.STANDARD_WIDTH && endTag)
		{
			largeTextSize = "<//h2>";
		}
		else if (System.getScreenWidth() == SCREEN_WIDTHS.STANDARD_WIDTH)
		{
			largeTextSize = "<h2>";
		}
		else if (endTag)
		{
			largeTextSize = "<//h4>";
		}
		else
		{
			largeTextSize = "<h4>";
		}
		
		return largeTextSize;
	}
	
	protected void hide()
	{
		_descriptionPanel.setVisible(false);
	}
}
